package com.anolesoft.yr.store.stk.util;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class StringUtil {
    public static int charsCount(String st,String M) {
        int count = 0;
        while(st.indexOf(M)>=0) {
            st=st.substring(st.indexOf(M)+M.length());
            count++;
        }
        return count    ;
    }
    //生成32位随机数
    public static String generateRundom32String(){
        UUID uuid=UUID.randomUUID();
        return uuid.toString().replace("-", "");
    }

    /**
     * 获取${}的值
     * @param str
     * @return
     */
    public static List<String> getVariable(String str) {
        Pattern pattern = Pattern.compile("\\$\\{([0-9a-zA-Z\\u4e00-\\u9fa5]*)\\}");
        Matcher matcher = pattern.matcher(str);
        List<String> values = new ArrayList<>();
        while (matcher.find()) {
            values.add( matcher.group().substring(2,matcher.group().length()-1));
        }
        return values;
    }

  /*  public static List<String> getLable(String str){
        Pattern pattern = Pattern.compile("<.*\\{1}>.*<.*>");
        Matcher matcher = pattern.matcher(str);
        List<String> values = new ArrayList<>();
        while (matcher.find()) {
            values.add( matcher.group().substring(2,matcher.group().length()-1));
        }
        return values;
    }*/

    public static void main(String[] args) {

        Pattern pattern = Pattern.compile(".*\\$\\{(.*)\\}.*");


//        List<String> variable = StringUtil.getVariable("gdfgdfgd${fdfsd}${王聪}gfgfgf");
//        String c = "<b>1<b>23</b>王嘉欣大帅哥，<<u>我";

    }
}
